package com.weiter.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weiter.common.core.core.page.PageQuery;
import com.weiter.system.domain.SysNotice;
import com.weiter.system.mapper.SysNoticeMapper;
import com.weiter.system.service.ISysNoticeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 通知公告
 * @author weiter
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {

    @Resource
    private SysNoticeMapper noticeMapper;

    /**
     * 查询通知公告分页列表
     * @param query     通知公告查询条件
     * @param pageQuery 分页查询信息
     * @return 通知公告分页列表
     */
    @Override
    public Page<SysNotice> selectNoticePage(SysNotice query, PageQuery pageQuery) {
        LambdaQueryWrapper<SysNotice> lqw = buildQueryWrapper(query);
        return noticeMapper.selectPage(pageQuery.build(), lqw);
    }

    private LambdaQueryWrapper<SysNotice> buildQueryWrapper(SysNotice query) {
        LambdaQueryWrapper<SysNotice> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(query.getNoticeTitle()), SysNotice::getNoticeTitle, query.getNoticeTitle());
        lqw.eq(StrUtil.isNotBlank(query.getNoticeType()), SysNotice::getNoticeType, query.getNoticeType());
        lqw.like(StrUtil.isNotBlank(query.getCreateBy()), SysNotice::getCreateBy, query.getCreateBy());
        lqw.orderByDesc(SysNotice::getCreateTime);
        return lqw;
    }
}
